#include "ShotCutTimeLine.h"

ShotCutTimeLine::ShotCutTimeLine(const Json::Value& TimeLineJsonInfo)
{
    if(TimeLineJsonInfo.isArray())
    {
        std::shared_ptr<GlobalData> Global = GlobalData::GetGlobalData();
        VideoTimeLine = make_shared<Timeline>(
                                        Global->GetVideoWidth(),
                                        Global->GetVideoHeight(),
                                        Fraction(Global->GetFps(), 1),
                                        Global->GetAudioSampleRate(),
                                        Global->GetAudioChannels(),
                                        Global->GetAudioChannelLayout());
    }
}

ShotCutTimeLine::~ShotCutTimeLine()
{
    if(VideoTimeLine)
    {
        if(VideoTimeLine->IsOpen())
        {
            VideoTimeLine->Close();
        }
    }
}

void ShotCutTimeLine::AttachVideoClips(const VideoClip& ShotCutClipInfo)
{
    for(auto ClipInfoItem : ShotCutClipInfo.VideoClipArray)
    {
        VideoTimeLine->AddClip(ClipInfoItem.second.get());
    }
}

void ShotCutTimeLine::AttachAudioClips(const AudioClip& ShotCutClipInfo)
{
    for(auto ClipInfoItem : ShotCutClipInfo.AudioClipArray)
    {
        VideoTimeLine->AddClip(ClipInfoItem.second.get());
    }
}

void ShotCutTimeLine::AttachVideoEffectClips(const VideoEffectClip& ShotCutEffectClipInfo)
{
    for(auto ClipInfoItem : ShotCutEffectClipInfo.VideoEffectClipArray)
    {
        VideoTimeLine->AddClip(ClipInfoItem.second.get());
    }
}

void ShotCutTimeLine::AttachMaskEffects(const MaskEffect& ShotCutEffectInfo)
{
    for(auto EffectInfoItem : ShotCutEffectInfo.MaskEffectArray)
    {
        VideoTimeLine->AddEffect(EffectInfoItem.second.get());
    }
}

void ShotCutTimeLine::AttachImageEffects(const ImageEffect& ShotCutImageEffectInfo)
{
    for(auto EffectInfoItem : ShotCutImageEffectInfo.ImageEffectArray)
    {
        VideoTimeLine->AddClip(EffectInfoItem.second.get());
    }
}

void ShotCutTimeLine::AttachFontEffects(const FontEffect& ShotCutFontEffectInfo)
{
    for(auto EffectInfoItem : ShotCutFontEffectInfo.FontEffectArray)
    {
        VideoTimeLine->AddEffect(EffectInfoItem.second.get());
    }
}

void ShotCutTimeLine::AttachCaption(const ShotCutCaption& ShotCutCaptionInfo)
{
    for(auto CaptionInfoItem : ShotCutCaptionInfo.CaptionArray)
    {
        VideoTimeLine->AddEffect(CaptionInfoItem.second.get());
    }
}
